package com.wjc.wjc.web;


import com.wjc.wjc.service.RecordService;
import com.wjc.wjc.unity.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class RecordsController {

    @Autowired
    private RecordService recordService;

    @GetMapping("/record")
    public String records(Model model){
        model.addAttribute("r",recordService.lsitReOp());
        return "record";
    }


    @PostMapping("/search/re")
    public String searchRe(@RequestParam String query,Model model){
        model.addAttribute("r",recordService.lsitRecord(query));
        return "/record :: record-fra";
    }


    @GetMapping("/cx/{name}")
    public String cx(@PathVariable String name, Model model){
        model.addAttribute("cx",recordService.lsitRecord(name));
        return "revoke";
    }

    @PostMapping("/cxbyid")
    public ModelAndView cxId(@RequestParam Long id, @RequestParam String remarks, @RequestParam String name){
        recordService.updataRemarks(id, remarks);
        List<Record> records=recordService.lsitRecord(name);
        return new ModelAndView("revoke","cx",records);
    }

}
